package main

import "fmt"

func main() {
	//us := [3]Usb{}
	//us[0] = Phone{Name: "vivo"}
	//us[1] = Phone{Name: "huawei"}
	//us[2] = Camera{Name: "佳能"}
	//
	//for _, v := range us {
	//	v.Start()
	//	//类型断言, 确保程序执行不会报错
	//	if phone, ok := v.(Phone); ok {
	//		phone.Call()
	//	}
	//	v.Stop()
	//	fmt.Println("---------------")
	//}

	test2()
}

//断言测试
func test2() {
	i := int32(32)
	j := int64(12)
	name := "zhangsan"
	f := float32(32.12)
	p := Phone{Name: "vivo"}
	TypeJudge(i, j, name, f, p)
}

//根据断言判断
func TypeJudge(items ...interface{}) {
	for index, v := range items {
		switch v.(type) {
		case bool:
			fmt.Printf("第%v个参数的类型是bool, 值是%v \n", index, v)
		case int8, int16, int32, int64:
			fmt.Printf("第%v个参数的类型是bool, 值是%v \n", index, v)
		case byte:
			fmt.Printf("第%v个参数的类型是bool, 值是%v \n", index, v)
		case string:
			fmt.Printf("第%v个参数的类型是bool, 值是%v \n", index, v)
		case Phone:
			fmt.Printf("第%v个参数的类型是Phone, 值是%v \n", index, v)
		case float64, float32:
			fmt.Printf("第%v个参数的类型是bool, 值是%v \n", index, v)
		default:
			fmt.Printf("第%v个参数的类型未知, 值是%v \n", index, v)
		}
	}
}

type Usb interface {
	Start()
	Stop()
}
type Phone struct {
	Name string
}

type Camera struct {
	Name string
}

func (p Phone) Start() {
	fmt.Printf("打开了%v手机 \n", p.Name)
}

func (p Phone) Stop() {
	fmt.Printf("关闭了%v手机 \n", p.Name)
}

func (p Phone) Call() {
	fmt.Printf("%v手机打电话 \n", p.Name)
}

func (c Camera) Start() {
	fmt.Printf("打开了%v相机 \n", c.Name)
}

func (c Camera) Stop() {
	fmt.Printf("关闭了%v相机 \n", c.Name)
}
